package com.jzr.task.job.shiyan;

import com.jzr.task.db1.mapper.MyPrimaryMapper;
import com.jzr.task.db1.mapper.TNurseMapper;
import com.jzr.task.db1.model.TNurse;
import com.jzr.task.db2.mapper.ShiyanMapper;
import com.jzr.task.db2.model.ShiyanNurse;
import com.jzr.task.job.BaseJob;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

@Component("Shiyan.SyncNurse")
public class ShiyanSyncNurse extends BaseJob {
    @Autowired
    private ShiyanMapper shiyanMapper;

    @Autowired
    private MyPrimaryMapper primaryMapper;

    @Autowired
    private TNurseMapper nurseMapper;

    @Override
    public void process() throws Exception {
        //同步护士
        List<ShiyanNurse> list = shiyanMapper.getNurseList();
        for(ShiyanNurse p : list){
            TNurse nurse = new TNurse();
            BeanUtils.copyProperties(p,nurse);
            nurse.setUpdateTime(LocalDateTime.now());
            Integer id = primaryMapper.getNurseId(p.getCode());
            if(id == null){
                nurseMapper.insert(nurse);
            }else{
                nurse.setId(id);
                nurseMapper.updateById(nurse);
            }
        }
    }
}